gl: Simplify glyph cache lookup
authorMatthias Clasen <mclasen@redhat.com>
Sat, 12 Oct 2019 05:35:13 +0000 (01:35 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Sat, 12 Oct 2019 05:35:13 +0000 (01:35 -0400)
Make this function more similar to the icon
cache equivalent, and simplify it a bit. We
don't use the boolean return, and we don't need
to look at the age of entry when marking it
used.

gsk/gl/gskglglyphcache.c
gsk/gl/gskglglyphcacheprivate.h
gsk/gl/gskglrenderer.c

index f7cb6fc2c6df69a48f63e1a388acde5619789ad7..21121b1ce5f06f88c0d886f91cb43214ee5a7a95 100644 (file)
@@ -252,11 +252,11 @@ add_to_cache (GskGLGlyphCache  *self,
   upload_glyph (key, value);
 }
 
-gboolean
-gsk_gl_glyph_cache_lookup (GskGLGlyphCache         *cache,
-                           GlyphCacheKey           *lookup,
-                           GskGLDriver             *driver,
-                           const GskGLCachedGlyph **cached_glyph_out)
+void
+gsk_gl_glyph_cache_lookup_or_add (GskGLGlyphCache         *cache,
+                                  GlyphCacheKey           *lookup,
+                                  GskGLDriver             *driver,
+                                  const GskGLCachedGlyph **cached_glyph_out)
 {
   GskGLCachedGlyph *value;
 
@@ -264,60 +264,54 @@ gsk_gl_glyph_cache_lookup (GskGLGlyphCache         *cache,
 
   if (value)
     {
-      const guint age = cache->timestamp - value->timestamp;
-
-      if (age > MAX_FRAME_AGE)
+      value->timestamp = cache->timestamp;
+      if (value->atlas && !value->used)
         {
-          if (value->atlas && !value->used)
-            {
-              gsk_gl_texture_atlas_mark_used (value->atlas, value->draw_width, value->draw_height);
-              value->used = TRUE;
-            }
+          gsk_gl_texture_atlas_mark_used (value->atlas, value->draw_width, value->draw_height);
+          value->used = TRUE;
         }
 
-      value->timestamp = cache->timestamp;
       *cached_glyph_out = value;
-    }
-  else
-    {
-      GlyphCacheKey *key;
-      PangoRectangle ink_rect;
-
-      pango_font_get_glyph_extents (lookup->font, lookup->glyph, &ink_rect, NULL);
-      pango_extents_to_pixels (&ink_rect, NULL);
-      if (lookup->xshift != 0)
-        ink_rect.width += 1;
-      if (lookup->yshift != 0)
-        ink_rect.height += 1;
-
-      value = g_new0 (GskGLCachedGlyph, 1);
-
-      value->draw_x = ink_rect.x;
-      value->draw_y = ink_rect.y;
-      value->draw_width = ink_rect.width;
-      value->draw_height = ink_rect.height;
-      value->timestamp = cache->timestamp;
-      value->atlas = NULL; /* For now */
-
-      key = g_new0 (GlyphCacheKey, 1);
-
-      key->font = g_object_ref (lookup->font);
-      key->glyph = lookup->glyph;
-      key->xshift = lookup->xshift;
-      key->yshift = lookup->yshift;
-      key->scale = lookup->scale;
-      key->hash = lookup->hash;
-
-      if (key->scale > 0 &&
-          value->draw_width * key->scale / 1024 > 0 &&
-          value->draw_height * key->scale / 1024 > 0)
-        add_to_cache (cache, key, driver, value);
-
-      *cached_glyph_out = value;
-      g_hash_table_insert (cache->hash_table, key, value);
+      return;
     }
 
-  return (*cached_glyph_out)->atlas != NULL;
+  {
+    GlyphCacheKey *key;
+    PangoRectangle ink_rect;
+
+    pango_font_get_glyph_extents (lookup->font, lookup->glyph, &ink_rect, NULL);
+    pango_extents_to_pixels (&ink_rect, NULL);
+    if (lookup->xshift != 0)
+      ink_rect.width += 1;
+    if (lookup->yshift != 0)
+      ink_rect.height += 1;
+
+    value = g_new0 (GskGLCachedGlyph, 1);
+
+    value->draw_x = ink_rect.x;
+    value->draw_y = ink_rect.y;
+    value->draw_width = ink_rect.width;
+    value->draw_height = ink_rect.height;
+    value->timestamp = cache->timestamp;
+    value->atlas = NULL; /* For now */
+
+    key = g_new0 (GlyphCacheKey, 1);
+
+    key->font = g_object_ref (lookup->font);
+    key->glyph = lookup->glyph;
+    key->xshift = lookup->xshift;
+    key->yshift = lookup->yshift;
+    key->scale = lookup->scale;
+    key->hash = lookup->hash;
+
+    if (key->scale > 0 &&
+        value->draw_width * key->scale / 1024 > 0 &&
+        value->draw_height * key->scale / 1024 > 0)
+      add_to_cache (cache, key, driver, value);
+
+    *cached_glyph_out = value;
+    g_hash_table_insert (cache->hash_table, key, value);
+  }
 }
 
 void
index dbe5196cca8ac210c6a5db471d9dc9ceaf95f0ce..259688fbb7e4911357ecea374ef23e42bc846e91 100644 (file)
@@ -74,7 +74,7 @@ GskGLGlyphCache *        gsk_gl_glyph_cache_ref             (GskGLGlyphCache *se
 void                     gsk_gl_glyph_cache_unref           (GskGLGlyphCache        *self);
 void                     gsk_gl_glyph_cache_begin_frame     (GskGLGlyphCache        *self,
                                                              GPtrArray              *removed_atlases);
-gboolean                 gsk_gl_glyph_cache_lookup          (GskGLGlyphCache        *self,
+void                     gsk_gl_glyph_cache_lookup_or_add   (GskGLGlyphCache        *self,
                                                              GlyphCacheKey          *lookup,
                                                              GskGLDriver            *driver,
                                                              const GskGLCachedGlyph **cached_glyph_out);
index 2600a35c903cb352484ad1b2fa8f3f321b917ab7..913472f3af81a97c70f1b2efd2fa59b56902537c 100644 (file)
@@ -587,10 +587,10 @@ render_text_node (GskGLRenderer   *self,
 
       glyph_cache_key_set_glyph_and_shift (&lookup, gi->glyph, x + cx, y + cy);
 
-      gsk_gl_glyph_cache_lookup (self->glyph_cache,
-                                 &lookup,
-                                 self->gl_driver,
-                                 &glyph);
+      gsk_gl_glyph_cache_lookup_or_add (self->glyph_cache,
+                                        &lookup,
+                                        self->gl_driver,
+                                        &glyph);
 
       if (glyph->texture_id == 0)
         goto next;